package com.asset.dispoal.user.service.commom;

import com.asset.dispoal.commom.page.PagingQuery;
import com.asset.dispoal.user.domain.db.mapper.SysUserMapper;
import com.asset.dispoal.user.dto.BsLawyerCourtRequest;
import com.asset.dispoal.user.dto.BsLawyerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.Page;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

import java.util.List;

/**
 * @author qr
 * @date 2022/5/16$
 */
@Component
public class QueryLawyerByCourtCommand implements BaseCommand<BsLawyerCourtRequest, Result<PageVO<BsLawyerResponse>>> {
    @Autowired
    SysUserMapper sysUserMapper;

    @Override
    public Result<PageVO<BsLawyerResponse>> execute(BsLawyerCourtRequest bsLawyerRequest) {
        int count = sysUserMapper.queryLawyerCountByCourtI(bsLawyerRequest.getCourtId(), bsLawyerRequest.getNickname(), bsLawyerRequest.getNo());
        Page<BsLawyerCourtRequest> page = PagingQuery.getPage(count, bsLawyerRequest);
        PageVO<BsLawyerResponse> pageVO = new PageVO<>();
        pageVO.setTotalSize(count);
        if (page != null) {
            List<BsLawyerResponse> bsLawyerResponses = sysUserMapper.queryLawyerByCourt(bsLawyerRequest.getCourtId(), bsLawyerRequest.getNickname(), bsLawyerRequest.getNo());
            pageVO.setResult(bsLawyerResponses);
        }
        return Result.ok(pageVO);
    }
}
